package com.ruoyi.mall.app.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.app.service.DtsUserService;
import com.ruoyi.mall.common.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user/userInfo")
public class DtsUserController extends BaseController {

    @Autowired
    private DtsUserService dtsUserService;

    @GetMapping("/userList")
    public AjaxResult list(int userId)
    {
        DtsUser list = dtsUserService.selectUserInfo(userId);
        if (list != null){
            return success(list);
        }else {
            return error();
        }
    }

    //商品收藏
    @GetMapping("/MyCollect")
    public AjaxResult MyCollect(DtsCollect dtsCollect)
    {
        // 判断是否有用户id
        if (dtsCollect.getUserId() == null){
            return success(0);
        }
        List<DtsGoods> list = dtsUserService.selectMyCollect(dtsCollect);
        if (list != null){
            return success(list);
        }else {
            return error();
        }
    }

    //意见反馈
    @GetMapping("/addFeedBack")
    public AjaxResult addFeedback(DtsFeedback feedback)
    {
        return toAjax(dtsUserService.addFeedback( feedback ));
    }

    //浏览足迹
    @GetMapping("/myFootprint")
    public AjaxResult myFootprint(int userId)
    {
        List<DtsGoods> list = dtsUserService.selectMyFootprint(userId);
        if (list != null){
            return success(list);
        }else {
            return error();
        }
    }

    //新增收藏
    @Log(title = "新增收藏", businessType = BusinessType.INSERT)
    @GetMapping("/addCollect")
    public AjaxResult addCollect(DtsCollect collect)
    {
        return toAjax(dtsUserService.addCollect(collect));
    }

    //取消收藏
    @Log(title = "取消收藏", businessType = BusinessType.UPDATE)
    @GetMapping("/delCollect")
    public AjaxResult delCollect(DtsCollect collect)
    {
        return toAjax(dtsUserService.delCollect(collect));
    }



}
